define('knowbase', [], function () {
    var Knowbase = {
        // 从列表中找到满足条件的数值 返回列表所在序号 找不到返回 -1
        getRandomStr: function (len) {
            len = len || 32;
            /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
            var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678$.!~@!^&*';
            var maxPos = $chars.length;
            var pwd = '';
            for (let i = 0; i < len; i++) {
                pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
            }
            return pwd;
        },
        unique: function (arr) {
            if (!Array.isArray(arr)) {
                return [];
            }
            var Arr = [];
            for (var i = 0; i < arr.length; i++) {
                if (Arr.indexOf(arr[i]) === -1) {
                    Arr.push(arr[i]);
                }
            }
            return Arr;
        },
        // 数组取交集 没有交集返回空数组
        array_intersection: function (arr1, arr2) {
            return arr1.filter(function (val1) {
                // 尝试将 val1 转换为数值
                var num1 = Number(val1);
                // 遍历 arr2，检查是否有与 val1 相等或者与 val1 的数值形式相等的元素
                for (var val2 of arr2) {
                    // 尝试将 val2 转换为数值
                    var num2 = Number(val2);
                    // 检查 val1 和 val2 是否相等（可能是字符串和字符串，数值和数值，或者字符串和数值）
                    if ((val1 === val2) || (num1 === num2)) {
                        return true;
                    }
                }
                return false;
            });
        },
        getCurrentTimeFormatted: function () {
            const now = new Date();
            let hours = now.getHours();
            let minutes = now.getMinutes();
            let seconds = now.getSeconds();

            // 确保小时数为两位数（如果需要）
            hours = hours < 10 ? '0' + hours : hours;
            minutes = minutes < 10 ? '0' + minutes : minutes;
            seconds = seconds < 10 ? '0' + seconds : seconds;

            return `${hours}:${minutes}:${seconds}`;
        },
        setStorage: function (key, value) {
            if (typeof (Storage) !== "undefined") {
                try {
                    sessionStorage.setItem(key, value);
                } catch (e) {
                    return null;
                }
            } else {
                return null;
            }
        },
        getStorage: function (key) {
            if (typeof (Storage) !== "undefined") {
                try {
                    return sessionStorage.getItem(key);
                } catch (e) {
                    return null;
                }
            } else {
                return null;
            }
        },
        removeStorage: function (key) {
            if (typeof (Storage) !== "undefined") {
                try {
                    return sessionStorage.removeItem(key);
                } catch (e) {
                    return null;
                }
            } else {
                return null;
            }
        },
        getId: function () {
            var s = window.location.href.substr(window.location.href.indexOf('ids/')+4);
            var pos = s.indexOf('?');
            if (pos>-1){
                s = s.substring(0,pos);
            }
            return s;
        }
    };
    return Knowbase;
});


